<?php
//    header("Content-Type:text/html;charset=utf-8");
//    error_reporting( E_ERROR | E_WARNING );
//    date_default_timezone_set("Asia/chongqing");
//    include "Uploader.class.php";
//    //上传配置
//    $config = array(
//        "savePath" => "upload/" ,             //存储文件夹
//        "maxSize" => 1000 ,                   //允许的文件最大尺寸，单位KB
//        "allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" )  //允许的文件格式
//    );
//    //上传文件目录
//    $Path = "upload/";
//
//    //背景保存在临时目录中
//    $config[ "savePath" ] = $Path;
//    $up = new Uploader( "upfile" , $config );
//    $type = $_REQUEST['type'];
//    $callback=$_GET['callback'];
//
//    $info = $up->getFileInfo();
//    /**
//     * 返回数据
//     */
//    if($callback) {
//        echo '<script>'.$callback.'('.json_encode($info).')</script>';
//    } else {
//        echo json_encode($info);
//    }

//<?php
    header("Content-Type:text/html;charset=utf-8");
    error_reporting( E_ERROR | E_WARNING );
    date_default_timezone_set("Asia/chongqing");
    include "Uploader.class.php";
    include "upyun.class.php";

    //上传配置
    $config = array(
        "savePath" => "../upload/" ,             //存储文件夹
        "maxSize" => 1000 ,                  //允许的文件最大尺寸，单位KB
        "allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" )  //允许的文件格式
    );

    $up = new Uploader( "upfile" , $config );
    $type = $_REQUEST['type'];
    $callback=$_GET['callback'];

    $info = $up->getFileInfo();

    $id=uniqid();
    $upyunDir = 'http://australiapic.b0.upaiyun.com/editor/';
    $upyun = new UpYun('australiapic', 'admin', 'hacker2016');
    $file_handler = fopen($info['url'], 'r');
    $upyun->writeFile('/editor/'.$id.'_'.$info['name'], $file_handler, true);
    fclose($file_handler);
    unlink("../upload/".date( "Ymd" ).'/'.$info['name']);//删除本地缓存
    $info['url']=$upyunDir.$id.'_'.$info['name'];

    /**
     * 返回数据
     */
    if($callback) {
        echo '<script> alert('.$callback.')'.'</script>';
//        echo '<script>'.$callback.'('.json_encode($info).')</script>';
    } else {
        echo json_encode($info);
    }


